//
//  WZQuestionDetailController.m
//  ETong
//
//  Created by wanzhao on 15/11/11.
//  Copyright (c) 2015年 wanzhao. All rights reserved.
//

#import "WZQuestionDetailController.h"
#import "MBProgressHUD+WZ.h"
#import "NetWorkShare.h"


@interface WZQuestionDetailController ()

@property (nonatomic, weak) UILabel *titleLabel;
@property (nonatomic, weak) UITextView *contentText;

@end

@implementation WZQuestionDetailController

- (void)dealloc
{
    NSLog(@"WZQuestionDetailController dealloc");
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.backgroundColor = RGBCOLORWITH16COLOR(0xeeeeee);
    self.navigationItem.title = @"答疑详情";
    
    
    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.frame = CGRectMake(OppositeWidthRate(10), 0, self.view.width - OppositeHeightRate(20), OppositeHeightRate(50));
    titleLabel.backgroundColor = ClearColor;
    titleLabel.font = Font18;
    titleLabel.textAlignment = NSTextAlignmentLeft;
    titleLabel.textColor = RGBCOLORWITH16COLOR(0x333333);
    [self.view addSubview:titleLabel];
    self.titleLabel = titleLabel;
    
    
    UIView *line1 = [[UIView alloc] init];
    line1.frame = CGRectMake(0, CGRectGetMaxY(titleLabel.frame), self.view.width, OppositeHeightRate(0.5));
    line1.backgroundColor = RGBCOLORWITH16COLOR(0xffffff);
    [self.view addSubview:line1];
    
    
    UIView *line2 = [[UIView alloc] init];
    line2.frame = CGRectMake(0, CGRectGetMaxY(line1.frame), self.view.width, OppositeHeightRate(0.5));
    line2.backgroundColor = RGBCOLORWITH16COLOR(0xd4d4d4);
    [self.view addSubview:line2];
    
    
    UITextView *contentLabel = [[UITextView alloc] init];
    contentLabel.userInteractionEnabled = NO;
    contentLabel.backgroundColor = ClearColor;
    contentLabel.frame = CGRectMake(OppositeWidthRate(10), CGRectGetMaxY(line2.frame), self.view.width - 2 * OppositeHeightRate(10), HARDWARE_SCREEN_HEIGHT - CGRectGetMaxY(line2.frame) - 64);
    contentLabel.font = Font15;
    contentLabel.textAlignment = NSTextAlignmentLeft;
    contentLabel.textColor = RGBCOLORWITH16COLOR(0x666666);
    [self.view addSubview:contentLabel];
    self.contentText = contentLabel;
    
    [self loadQuestionDetail];
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
        
}


- (void)loadQuestionDetail
{
    
    __block typeof(self) weakSelf = self;
    [MBProgressHUD showMessage:nil toView:self.view];
    [NetWorkShare getQuestionDetailWithQuestionID:self.questionId successHandle:^(AFHTTPRequestOperation *operation, id responseObject) {
        [MBProgressHUD hideHUDForView:self.view];
        if (responseObject) {
            
            if ([[responseObject objectForKey:@"success"] boolValue]) {
                
                NSDictionary *dict = [responseObject objectForKey:@"problemInfo"];
                
                weakSelf.titleLabel.text = [dict objectForKey:@"title"];
                weakSelf.contentText.text = [dict objectForKey:@"content"];
                
            } else {
                [MBProgressHUD showError:[responseObject objectForKey:@"message"]];
            }
            
        } else {
            [MBProgressHUD showError:@"未知错误"];
        }
        
    } failureHandle:^(AFHTTPRequestOperation *operation, NSError *error) {
        
        [MBProgressHUD hideHUDForView:self.view];
        [MBProgressHUD showError:@"网络错误"];
    }];
}

@end
